package com.xhtranslate.common.config;

import com.xhtranslate.common.filter.ImageTranslateFilter;
import com.xhtranslate.common.filter.OcrFilter;
import com.xhtranslate.common.filter.TextTranslateFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author liuxuhuang
 * @version 1.0
 * @package com.xhtranslate.common.filter
 * @date 2022/11/20 23:07:22
 * @description 百度filter
 */
@Component
public class FilterConfig {
    @Autowired
    private OcrFilter ocrFilter;
    @Autowired
    private TextTranslateFilter textTranslateFilter;
    @Autowired
    private ImageTranslateFilter imageTranslateFilter;

    @Bean
    public FilterRegistrationBean ocrFilterBean() {
        FilterRegistrationBean<OcrFilter> bean = new FilterRegistrationBean<>(ocrFilter);
        bean.addUrlPatterns("/baiduOcr/baiduOCR");
        bean.addUrlPatterns("/youdaoOcr/ocr");
        bean.addUrlPatterns("/aliOcr/ocr");
        return bean;
    }

    @Bean
    public FilterRegistrationBean imageTranslateFilterBean() {
        FilterRegistrationBean<ImageTranslateFilter> bean = new FilterRegistrationBean<>(imageTranslateFilter);
        bean.addUrlPatterns("/baiduTranslate/imageTranslate");
        bean.addUrlPatterns("/alitranslate/imageTranslate");
        bean.addUrlPatterns("/youdaoTranslate/imageTranslate");
        return bean;
    }

    @Bean
    public FilterRegistrationBean textTranslateFilterBean() {
        FilterRegistrationBean<TextTranslateFilter> bean = new FilterRegistrationBean<>(textTranslateFilter);
        bean.addUrlPatterns("/baiduTranslate/commonTranslate");
        bean.addUrlPatterns("/aliTranslate/commonTranslate");
        bean.addUrlPatterns("/youdaoTranslate/textTranslate");
        return bean;
    }
}
